package com.ktg.mes.pda.service.impl;

import java.util.Arrays;
import java.util.List;
import com.ktg.common.utils.DateUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ktg.common.utils.SecurityUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktg.mes.pda.mapper.PdaLabelTypeMapper;
import com.ktg.mes.pda.domain.PdaLabelType;
import com.ktg.mes.pda.service.IPdaLabelTypeService;



/**
 * PDA采集标签说明Service业务层处理
 *
 * @author byteco
 * @date 2023-02-24
 */
@Service
public class PdaLabelTypeServiceImpl extends ServiceImpl<PdaLabelTypeMapper, PdaLabelType> implements IPdaLabelTypeService
{




    /**
     * 查询PDA采集标签说明
     *
     * @param entity PDA采集标签说明
     * @param page 分页对象
     * @return PDA采集标签说明
     */
    @Override
    public IPage<PdaLabelType> queryPageList(PdaLabelType entity, Page<PdaLabelType> page) {
        QueryWrapper<PdaLabelType> lqw = new QueryWrapper<PdaLabelType>(entity);
        lqw.orderByDesc("create_time");
        IPage<PdaLabelType> pageList = this.page(page, lqw);
        return pageList;
    }

    /**
     * 查询PDA采集标签说明
     *
     * @param entity PDA采集标签说明
     * @return PDA采集标签说明
     */
    @Override
    public List<PdaLabelType> queryList(PdaLabelType entity) {
        QueryWrapper<PdaLabelType> lqw = new QueryWrapper<PdaLabelType>(entity);
        lqw.orderByDesc("create_time");
        return this.list(lqw);
    }

    public PdaLabelType getInfo(Long id)
    {
        return this.getById(id);
    }


    /**
     * 新增PDA采集标签说明
     *
     * @param entity PDA采集标签说明
     * @return 结果
     */
    @Override
    public void insert(PdaLabelType entity)
    {
        entity.setCreateBy(SecurityUtils.getUsername());
        entity.setCreateTime(DateUtils.getNowDate());
        this.save(entity);
    }

    /**
     * 修改PDA采集标签说明
     *
     * @param entity PDA采集标签说明
     * @return 结果
     */
    @Override
    public boolean update(PdaLabelType entity)
    {
        entity.setUpdateBy(SecurityUtils.getUsername());
        entity.setUpdateTime(DateUtils.getNowDate());
        return this.updateById(entity);
    }

    /**
     * 批量删除PDA采集标签说明
     *
     * @param recordIds 需要删除的PDA采集标签说明主键
     * @return 结果
     */
    @Override
    public boolean delete(Long[] recordIds)
    {

        return this.removeByIds(Arrays.asList(recordIds));
    }

    /**
     * 删除PDA采集标签说明信息
     *
     * @param recordId PDA采集标签说明主键
     * @return 结果
     */
    @Override
    public boolean delete(Long recordId)
    {
        return this.removeById(recordId);
    }

    private LambdaQueryWrapper<PdaLabelType> buildQueryWrapper(PdaLabelType entity) {
        LambdaQueryWrapper<PdaLabelType> lqw = Wrappers.lambdaQuery();
                    lqw.like(StringUtils.isNotBlank(entity.getName()), PdaLabelType::getName, entity.getName());
                    lqw.eq(StringUtils.isNotBlank(entity.getFirstCode()), PdaLabelType::getFirstCode, entity.getFirstCode());
                    lqw.eq(StringUtils.isNotBlank(entity.getLabelRule()), PdaLabelType::getLabelRule, entity.getLabelRule());
                    lqw.eq(StringUtils.isNotBlank(entity.getLabelExample()), PdaLabelType::getLabelExample, entity.getLabelExample());
        return lqw;
    }
}
